// SPDX-License-Identifier: GPL-2.0-only
/*
 * Example code for CSV RTMR & ATTESTATION.
 *
 * Copyright (C) 2025 Hygon Info Technologies Ltd.
 *
 * Author: Liyang Han <hanliyang@hygon.cn>
 */

#ifndef __CSV_GUEST_TOOL_H__
#define __CSV_GUEST_TOOL_H__

#include <linux/types.h>
#include <linux/ioctl.h>

#ifdef DEBUG
#define PR_DEBUG(fmt, ...)	\
	fprintf(stdout, "[DEBUG] %s: " fmt, __func__, ##__VA_ARGS__)
#else
#define PR_DEBUG(fmt, ...)
#endif
#define PR_INFO(fmt, ...)	\
	fprintf(stdout, "[INFO]  %s: " fmt, __func__, ##__VA_ARGS__)
#define PR_WARN(fmt, ...)	\
	fprintf(stderr, "[WARN]  %s: " fmt, __func__, ##__VA_ARGS__)
#define PR_ERR(fmt, ...)	\
	fprintf(stderr, "[ERROR] %s: " fmt, __func__, ##__VA_ARGS__)

#define APP_SUBCMD_HELP		"help"
#define APP_SUBCMD_RTMR		"rtmr"
#define APP_SUBCMD_ATTESTATION	"attestation"

#define CSV_GUEST_DEV_PATH	"/dev/csv-guest"
#define DEV_MEM			"/dev/mem"
#define PAGE_SIZE		(1ULL << 12)

/* Macro to check structure size */
#define CHECK_STRUCT_SIZE(type, size) \
	typedef char __check_##type[((sizeof(type) == (size)) * 2 - 1)]

extern char *g_prog_name;

int open_csv_guest(void);
int convert_ascii_str_to_bin(uint8_t *buffer, int buffer_len,
			     const char *str, int str_len);
int gen_random_data(void *buffer, uint32_t len);
void dump_bin(uint8_t *buffer, int buffer_len);

#endif  /* __CSV_GUEST_TOOL_H__ */
